home *** CD-ROM | disk | FTP | other *** search
Oberon Text | 1990-10-18 | 4.1 KB | 106 lines | [.Ob./.Ob2] |
- Syntax10.Scn.Fnt
- MODULE EdT; (* Robert Griesemer / Michael Franz, 1.9.90 *)
- Simple Extension of Edit which supports
- - Auto-Indentation
- - Cursor Keys for Caret Movement
- - Indentation Control of Text Selections by use of Cursor Keys
- (Viewer must be in focus, i.e. contain Caret)
- Once you have compiled this module, you may use the command
- EdT.Open name
- EdT.Open ^
- instead of Edit.Open for opening files in the enhanced Editor.
- IMPORT
- Display, Viewers, Texts, TextFrames, MenuViewers, Oberon;
- CONST
- HT = 9X; LF = 0AX; CR = 0DX; Left = 01CX; Right = 01DX;
- Menu = "System.Close System.Copy System.Grow Edit.Store";
- TYPE
- EdTMsg = RECORD(Display.FrameMsg)
- text: Texts.Text;
- beg, end: LONGINT;
- time: LONGINT
- END;
- W: Texts.Writer;
- PROCEDURE BegOfLine(text: Texts.Text; pos: LONGINT): LONGINT;
- VAR r: Texts.Reader; ch: CHAR;
- BEGIN
- LOOP DEC(pos);
- IF pos < 0 THEN RETURN 0 END;
- Texts.OpenReader(r, text, pos); Texts.Read(r, ch);
- IF ch = CR THEN RETURN pos+1 END
- END
- END BegOfLine;
- PROCEDURE Select(text: Texts.Text; beg, end: LONGINT);
- VAR msg: EdTMsg;
- BEGIN msg.text := text; msg.beg := beg; msg.end := end; msg.time := Oberon.Time(); Viewers.Broadcast(msg)
- END Select;
- PROCEDURE Move(f: TextFrames.Frame; dx: INTEGER);
- VAR text: Texts.Text; beg, end, time, pos: LONGINT; r: Texts.Reader; ch: CHAR;
- BEGIN Oberon.GetSelection(text, beg, end, time);
- IF (time >= 0) & (f.text = text) THEN beg := BegOfLine(text, beg); pos := beg; (* move selection *)
- WHILE pos < end DO Texts.OpenReader(r, text, pos); Texts.Read(r, ch);
- IF dx < 0 THEN
- IF (ch <= " ") & (ch # CR) THEN Texts.Delete(text, pos, pos+1); DEC(end) END
- ELSE
- IF (ch <= " ") & (ch # CR) THEN Texts.Write(W, ch) ELSE Texts.Write(W, HT) END; (* first char extension *)
- Texts.Insert(text, pos, W.buf); INC(end); INC(pos)
- END;
- Texts.OpenReader(r, text, pos);
- REPEAT Texts.Read(r, ch) UNTIL r.eot OR (ch = CR);
- pos := Texts.Pos(r)
- END;
- Select(text, beg, pos)
- ELSIF f.car > 0 THEN pos := f.carloc.pos+dx; (* move caret *)
- IF pos < 0 THEN pos := 0 ELSIF pos > f.text.len THEN pos := f.text.len END;
- TextFrames.RemoveCaret(f); TextFrames.SetCaret(f, pos)
- END
- END Move;
- PROCEDURE NewLine(f: TextFrames.Frame);
- VAR r: Texts.Reader; n, car: LONGINT; ch: CHAR;
- BEGIN Texts.Write(W, CR); car := f.carloc.pos+1; Texts.OpenReader(r, f.text, f.carloc.org); Texts.Read(r, ch);
- WHILE (Texts.Pos(r) <= f.carloc.pos) & (ch <= " ") DO Texts.Write(W, ch); INC(car); Texts.Read(r, ch) END;
- Texts.Insert(f.text, f.carloc.pos, W.buf); TextFrames.SetCaret(f, car)
- END NewLine;
- PROCEDURE Handle*(F: Display.Frame; VAR msg: Display.FrameMsg);
- BEGIN
- WITH F: TextFrames.Frame DO
- IF msg IS Oberon.InputMsg THEN
- WITH msg: Oberon.InputMsg DO
- IF msg.id = Oberon.consume THEN
- IF msg.ch = Left THEN Move(F, -1)
- ELSIF msg.ch = Right THEN Move(F, 1)
- ELSIF F.car > 0 THEN (* caret set *)
- IF msg.ch = LF THEN msg.ch := CR; TextFrames.Handle(F, msg)
- ELSIF msg.ch = CR THEN NewLine(F)
- ELSE TextFrames.Handle(F, msg)
- END
- END
- ELSE TextFrames.Handle(F, msg)
- END
- END
- ELSIF msg IS EdTMsg THEN
- WITH msg: EdTMsg DO
- IF (F.text = msg.text) & (F.sel = 0) THEN TextFrames.SetSelection(F, msg.beg, msg.end); F.time := msg.time END
- END
- ELSE TextFrames.Handle(F, msg)
- END
- END
- END Handle;
- PROCEDURE Open*;
- VAR S: Texts.Scanner; T: Texts.Text; V: MenuViewers.Viewer; x, y: INTEGER; beg, end, time: LONGINT;
- BEGIN Texts.OpenScanner(S, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(S);
- IF (S.class = Texts.Char) & (S.c = "^") OR (S.line # 0) THEN Oberon.GetSelection(T, beg, end, time);
- IF time >= 0 THEN Texts.OpenScanner(S, T, beg); Texts.Scan(S) END
- END;
- IF S.class = Texts.Name THEN Oberon.AllocateUserViewer(Oberon.Mouse.X, x, y);
- V := MenuViewers.New(
- TextFrames.NewMenu(S.s, Menu),
- TextFrames.NewText(TextFrames.Text(S.s), 0),
- TextFrames.menuH, x, y);
- V.dsc.next.handle := Handle
- END
- END Open;
- BEGIN
- Texts.OpenWriter(W)
- END EdT.
-